package com.kaiwukj.android.ufamily.mvp.ui.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatImageView;

import com.blankj.utilcode.util.SizeUtils;

public class RadiusImageView extends AppCompatImageView {

    private float topLeftRadius = SizeUtils.dp2px(12);
    private float topRightRadius = SizeUtils.dp2px(12);

    private float[] rids = {topLeftRadius, topLeftRadius, topRightRadius, topRightRadius, 0.0f, 0.0f, 0.0f, 0.0f,};

    public RadiusImageView(@NonNull Context context) {
        super(context);
    }

    public RadiusImageView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public RadiusImageView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        Path path = new Path();
        int w = this.getWidth();
        int h = this.getHeight();
        path.addRoundRect(new RectF(0, 0, w, h), rids, Path.Direction.CW);
        canvas.clipPath(path);
        super.onDraw(canvas);
    }
}
